package face.pay.cpn.activity.service.impl;

import face.pay.cpn.AbstractApiService;
import face.pay.cpn.activity.service.IActivityInfoService;
import face.pay.cpn.utils.request.RequestParam;
import face.pay.cpn.utils.response.ErrorCode;
import face.pay.cpn.utils.response.ResponseMessage;
import face.pay.dao.CpnActivityInfoDao;
import face.pay.entity.CpnMarketInfo;
import face.pay.util.DateUtil;
import face.pay.vo.VoActivityInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;


@Service
@Slf4j
public class ActivityInfoServiceImpl extends AbstractApiService implements IActivityInfoService {


    @Autowired
    private CpnActivityInfoDao cpnActivityInfoDao;


    /**
     * 查询活动详情
     *
     * @param jsonData
     * @return
     */
    @Override
    public ResponseMessage queryActivityInfo(String jsonData) {
        return doApi(jsonData);
    }

    @Override
    public ResponseMessage doService(CpnMarketInfo cpnMarketInfo, RequestParam requestParam) throws Exception {

        String satartTime = requestParam.getData().get("queryTime").toString();

        if (DateUtil.dateParse(satartTime, "yyyy-MM-dd HH:mm:ss") == null) {
            return ResponseMessage.createFail(ErrorCode.PARAM_FAIL_CODE, "查询时间格式有误!");
        }
        log.info(">>>>>>开始查找活动详情 market_id :{}", cpnMarketInfo.getId());
        HashMap<String, Object> activityRecord = new HashMap<>();
        activityRecord.put("market_id", cpnMarketInfo.getId());
        activityRecord.put("satartTime", satartTime);

        List<VoActivityInfo> dataList = this.cpnActivityInfoDao.queryActivityInfoList(activityRecord);
        log.info("<<<<<<<结束查找活动详情 market_id :{} 共查到:{} 条", cpnMarketInfo.getId(), dataList.size());
        return ResponseMessage.createSuccess(dataList);
    }

}
